using DG.Tweening;
using Spine;
using Spine.Unity;
using Spine.Unity.Modules;
using System;
using System.Collections;
using UnityEngine;

public class EnemyController : MonoBehaviour
{
	public GameObject[] Item;

	public GameObject Bow;

	public GameObject Bom;

	public GameObject Laze;

	public GameObject childLaze;

	public GameObject EffHitOfBoss4;

	public GameObject EffSkillUltoBoss4;

	public GameObject effHitlaze;

	public GameObject blood;

	public GameObject blood1;

	private GameObject lazeBoss3;

	private GameObject childLazeBoss3;

	private GameObject bcLaze;

	private GameObject[] player;

	private GameObject _target;

	private Vector3 posPlayer;

	public tk2dClippedSprite ClipHealthEnemy;

	private SkeletonAnimation skeletonAnimationHead;

	private bool isLaze;

	private bool isEff;

	private bool isattack;

	private bool isMet;

	private bool ishurt;

	private bool isdeath;

	private bool isNga;

	private bool isNotSkill;

	private bool isSkill;

	private bool isAttacking;

	private bool isComplete = true;

	private bool chuyen;

	private float distance;

	public float speed = 1.5f;

	public float distanceAttack;

	public float HealthMaxEnemy;

	private float localHealthEnemy;

	private float currentTime;

	private float[] healthMonster = new float[31]
	{
		500f,
		500f,
		550f,
		600f,
		600f,
		650f,
		800f,
		800f,
		900f,
		900f,
		1000f,
		1200f,
		1200f,
		1300f,
		1400f,
		400f,
		400f,
		450f,
		550f,
		1000f,
		1100f,
		1200f,
		1400f,
		1500f,
		1500f,
		3600f,
		3500f,
		4000f,
		15000f,
		15000f,
		30000f
	};

	private float[] Heso = new float[61]
	{
		1f,
		2f,
		2.2f,
		2.5f,
		2.5f,
		3f,
		3f,
		4f,
		5f,
		5f,
		5.5f,
		6.5f,
		7.5f,
		8.5f,
		9.5f,
		10f,
		11.5f,
		12f,
		13f,
		14f,
		12f,
		13f,
		14f,
		15f,
		20f,
		23f,
		25f,
		30f,
		36f,
		42f,
		45f,
		50f,
		56f,
		62f,
		70f,
		75f,
		80f,
		85f,
		90f,
		100f,
		120f,
		130f,
		140f,
		150f,
		170f,
		190f,
		210f,
		220f,
		240f,
		250f,
		300f,
		330f,
		380f,
		400f,
		450f,
		480f,
		510f,
		540f,
		570f,
		600f,
		45f
	};

	private int countNga;

	private int countAttack;

	private int AttackOfBoss4;

	private int attackofBoss5;

	private int attackofBoss6;

	private int HitOfBoss4;

	private int attackofBoss3;

	public int typeOfEnemy;

	private int dropcoin;

	private int hesoHard;

	public int damageEnemy;

	private int[] damageEnemyNormal = new int[31]
	{
		25,
		25,
		35,
		35,
		35,
		40,
		45,
		45,
		60,
		70,
		70,
		80,
		90,
		90,
		90,
		0,
		0,
		0,
		50,
		80,
		80,
		90,
		75,
		80,
		85,
		180,
		225,
		1000,
		300,
		750,
		750
	};

	private readonly string[][] AnimationName = new string[31][]
	{
		new string[6]
		{
			"Cr_Walk",
			"Cr_hit",
			"CR_nga",
			"Cr_attack",
			"Cr_attack_2",
			"CR_dung len"
		},
		new string[6]
		{
			"Cr_Walk",
			"Cr_hit",
			"CR_nga",
			"Cr_attack",
			"Cr_attack_2",
			"CR_dung len"
		},
		new string[6]
		{
			"Cr_Walk",
			"Cr_hit",
			"CR_nga",
			"Cr_attack",
			"Cr_attack_2",
			"CR_dung len"
		},
		new string[6]
		{
			"Chay_Walk",
			"Chay_hit",
			"Chay_nga",
			"Chay_attack",
			"Chay_attack2",
			"Chay_dung len"
		},
		new string[6]
		{
			"Chay_Walk",
			"Chay_hit",
			"Chay_nga",
			"Chay_attack",
			"Chay_attack2",
			"Chay_dung len"
		},
		new string[6]
		{
			"Chay_Walk",
			"Chay_hit",
			"Chay_nga",
			"Chay_attack",
			"Chay_attack2",
			"Chay_dung len"
		},
		new string[6]
		{
			"Cr_Walk",
			"Cr_hit",
			"Cr_nga",
			"Cr_attack_1",
			"Cr_attack_2",
			"Cr_dung len"
		},
		new string[6]
		{
			"Cr_Walk",
			"Cr_hit",
			"Cr_nga",
			"Cr_attack_1",
			"Cr_attack_2",
			"Cr_dung len"
		},
		new string[6]
		{
			"Cr_Walk",
			"Cr_hit",
			"Cr_nga",
			"Cr_attack_1",
			"Cr_attack_2",
			"Cr_dung len"
		},
		new string[6]
		{
			"Cr_walk",
			"CR_hit",
			"Cr_nga",
			"Cr_attack_1",
			"Cr_attack_2",
			"Cr_dung day"
		},
		new string[6]
		{
			"Cr_walk",
			"CR_hit",
			"Cr_nga",
			"Cr_attack_1",
			"Cr_attack_2",
			"Cr_dung day"
		},
		new string[6]
		{
			"Cr_walk",
			"CR_hit",
			"Cr_nga",
			"Cr_attack_1",
			"Cr_attack_2",
			"Cr_dung day"
		},
		new string[6]
		{
			"Cr_Walk",
			"Cr_hit",
			"CR_nga",
			"Cr_attack",
			"Cr_attack2",
			"CR_dung len"
		},
		new string[6]
		{
			"Cr_Walk",
			"Cr_hit",
			"CR_nga",
			"Cr_attack",
			"Cr_attack2",
			"CR_dung len"
		},
		new string[6]
		{
			"Cr_Walk",
			"Cr_hit",
			"CR_nga",
			"Cr_attack",
			"Cr_attack2",
			"CR_dung len"
		},
		new string[5]
		{
			"Cr_Walk",
			"Cr_hit",
			"CR_nga",
			"Cr_attack",
			"CR_dung len"
		},
		new string[5]
		{
			"Cr_Walk",
			"Cr_hit",
			"CR_nga",
			"Cr_attack",
			"CR_dung len"
		},
		new string[5]
		{
			"Cr_Walk",
			"Cr_hit",
			"CR_nga",
			"Cr_attack",
			"CR_dung len"
		},
		new string[5]
		{
			"Cr_walk",
			"CR_hit",
			"Cr_nga",
			"Cr_attack_3",
			"Cr_dung day"
		},
		new string[6]
		{
			"walk",
			"hit",
			"down",
			"attack1",
			"attack2",
			"up"
		},
		new string[6]
		{
			"walk",
			"hit",
			"down",
			"attack1",
			"attack2",
			"up"
		},
		new string[6]
		{
			"walk",
			"hit",
			"down",
			"attack1",
			"attack2",
			"up"
		},
		new string[5]
		{
			"walk",
			"hit",
			"down",
			"attack1",
			"up"
		},
		new string[5]
		{
			"walk",
			"hit",
			"down",
			"attack1",
			"up"
		},
		new string[5]
		{
			"walk",
			"hit",
			"down",
			"attack1",
			"up"
		},
		new string[3]
		{
			"di",
			"attack",
			"die"
		},
		new string[4]
		{
			"run",
			"attack",
			"die",
			"attack2"
		},
		new string[5]
		{
			"dung im2",
			"attack",
			"die",
			"attack2",
			"attack3"
		},
		new string[8]
		{
			"dung im",
			"attack1",
			"die",
			"attack2",
			"attack3",
			"ulti",
			"met",
			"up"
		},
		new string[5]
		{
			"run",
			"attack",
			"die",
			"dung im",
			"attack 2"
		},
		new string[5]
		{
			"run",
			"attack 1",
			"die",
			"dung im",
			"attack 2"
		}
	};

	public event EventHandler EnemyKilled;

	private void OnEnable()
	{
		int num = 1;
		if (!GameManager.isHard)
		{
			hesoHard = 1;
			num = 1;
		}
		else
		{
			hesoHard = 1;
			num = 2;
		}
		Init();
		isdeath = false;
		distanceAttack += UnityEngine.Random.Range(-0.1f, 0.21f);
		HealthMaxEnemy = healthMonster[typeOfEnemy] * Heso[GameManager.stage - 1] * (float)num;
		if (GameManager.stage < 41)
		{
			damageEnemy = damageEnemyNormal[typeOfEnemy] / 4 * GameManager.stage * hesoHard;
		}
		else if (GameManager.stage >= 41 && GameManager.stage < 51)
		{
			damageEnemy = damageEnemyNormal[typeOfEnemy] / 3 * GameManager.stage * hesoHard;
		}
		else if (GameManager.stage >= 51 && GameManager.stage < 61)
		{
			damageEnemy = damageEnemyNormal[typeOfEnemy] / 2 * GameManager.stage * hesoHard;
		}
		else
		{
			damageEnemy = damageEnemyNormal[typeOfEnemy] / 4 * GameManager.stage * hesoHard;
		}
		localHealthEnemy = HealthMaxEnemy;
	}

	private void OnDisable()
	{
		GetComponent<SkeletonAnimation>().state.Complete -= AnimationComplete;
	}

	private void SetColor(int idColor)
	{
		Color color = (idColor == 1) ? Color.blue : new Color(1f, 0.6f, 0f, 1f);
		if (typeOfEnemy >= 12 && typeOfEnemy < 15)
		{
			skeletonAnimationHead.skeleton.FindSlot("en").SetColor(color);
		}
		else
		{
			skeletonAnimationHead.skeleton.FindSlot("Creep_head").SetColor(color);
		}
		skeletonAnimationHead.skeleton.FindSlot("Creep_leg").SetColor(color);
		skeletonAnimationHead.skeleton.FindSlot("Creep_leg2").SetColor(color);
		skeletonAnimationHead.skeleton.FindSlot("Creep_leg3").SetColor(color);
		skeletonAnimationHead.skeleton.FindSlot("Creep_leg4").SetColor(color);
		skeletonAnimationHead.skeleton.FindSlot("Creep_mu").SetColor(color);
		skeletonAnimationHead.skeleton.FindSlot("Creep_mu2").SetColor(color);
		skeletonAnimationHead.skeleton.FindSlot("Creep_hand").SetColor(color);
		skeletonAnimationHead.skeleton.FindSlot("Creep_hand2").SetColor(color);
		skeletonAnimationHead.skeleton.FindSlot("Creep_hand3").SetColor(color);
		skeletonAnimationHead.skeleton.FindSlot("Creep_hand4").SetColor(color);
		skeletonAnimationHead.skeleton.FindSlot("Creep_hand5").SetColor(color);
		skeletonAnimationHead.skeleton.FindSlot("Creep_hand6").SetColor(color);
	}

	private void Init()
	{
		player = GameObject.FindGameObjectsWithTag("Player");
		if (GameManager.Dog > 0)
		{
			dropcoin = 50;
		}
		else
		{
			dropcoin = 30;
		}
	}

	private void Start()
	{
		skeletonAnimationHead = GetComponent<SkeletonAnimation>();
		skeletonAnimationHead.state.Complete += AnimationComplete;
		skeletonAnimationHead.state.Event += ActiveSkill;
		if (typeOfEnemy == 4 || typeOfEnemy == 7 || typeOfEnemy == 10 || typeOfEnemy == 13 || typeOfEnemy == 16 || typeOfEnemy == 20 || typeOfEnemy == 23)
		{
			SetColor(1);
		}
		else if (typeOfEnemy == 5 || typeOfEnemy == 8 || typeOfEnemy == 11 || typeOfEnemy == 14 || typeOfEnemy == 17 || typeOfEnemy == 18 || typeOfEnemy == 21 || typeOfEnemy == 24)
		{
			SetColor(2);
		}
	}

	private void Update()
	{
		currentTime += Time.deltaTime;
		if (GameManager.isWin && !isdeath)
		{
			Hit_Player(10000000, a: true, 2);
		}
		if (isdeath)
		{
			if (typeOfEnemy >= 25)
			{
				GetComponent<SkeletonAnimation>().AnimationName = AnimationName[typeOfEnemy][2];
			}
			GameManager.AllEnemy.Remove(base.gameObject);
		}
		if (isdeath)
		{
			return;
		}
		if (_target == null)
		{
			FindPlayer();
		}
		else
		{
			Vector3 position = base.transform.position;
			float x = position.x;
			Vector3 position2 = _target.transform.position;
			distance = Mathf.Abs(x - position2.x);
		}
		if (typeOfEnemy < 15 || (typeOfEnemy > 18 && typeOfEnemy < 22))
		{
			if (!isattack && !ishurt && !isNotSkill && isComplete && !isAttacking)
			{
				Vector3 position3 = base.transform.position;
				float x2 = position3.x;
				Vector3 position4 = _target.transform.position;
				if (x2 < position4.x)
				{
					base.transform.Translate(Vector2.right * speed * Time.deltaTime);
					GetComponent<SkeletonAnimation>().skeleton.FlipX = false;
				}
				else
				{
					base.transform.Translate(-Vector2.right * speed * Time.deltaTime);
					GetComponent<SkeletonAnimation>().skeleton.FlipX = true;
				}
				SetAnim(AnimationName[typeOfEnemy][0], loop: true);
			}
			if (distance < distanceAttack && _target != null && !ishurt && !isNotSkill && isComplete)
			{
				isattack = true;
				isAttacking = true;
				FlipEnemy();
				if (GetComponent<SkeletonAnimation>().AnimationName != AnimationName[typeOfEnemy][3] && countAttack == 0 && !chuyen)
				{
					GetComponent<SkeletonAnimation>().state.SetAnimation(0, AnimationName[typeOfEnemy][3], loop: false);
					chuyen = true;
				}
				else if (GetComponent<SkeletonAnimation>().AnimationName != AnimationName[typeOfEnemy][4] && countAttack == 1 && chuyen)
				{
					GetComponent<SkeletonAnimation>().state.SetAnimation(0, AnimationName[typeOfEnemy][4], loop: false);
				}
			}
			if (distance > distanceAttack && _target != null)
			{
				isattack = false;
			}
		}
		else if (typeOfEnemy >= 15 && typeOfEnemy <= 18)
		{
			if (!isattack && !ishurt && !isNotSkill && isComplete)
			{
				Vector3 position5 = base.transform.position;
				float x3 = position5.x;
				Vector3 position6 = _target.transform.position;
				if (x3 < position6.x)
				{
					base.transform.Translate(Vector2.right * speed * Time.deltaTime);
					GetComponent<SkeletonAnimation>().skeleton.FlipX = false;
				}
				else
				{
					base.transform.Translate(-Vector2.right * speed * Time.deltaTime);
					GetComponent<SkeletonAnimation>().skeleton.FlipX = true;
				}
				SetAnim(AnimationName[typeOfEnemy][0], loop: true);
			}
			if (distance < distanceAttack && _target != null && !ishurt && !isNotSkill)
			{
				isattack = true;
				FlipEnemy();
				SetAnim(AnimationName[typeOfEnemy][3], loop: true);
			}
			if (distance > distanceAttack && _target != null)
			{
				isattack = false;
			}
		}
		else if (typeOfEnemy >= 22 && typeOfEnemy < 25)
		{
			if (!isattack && !ishurt && !isNotSkill && isComplete)
			{
				Vector3 position7 = base.transform.position;
				float x4 = position7.x;
				Vector3 position8 = _target.transform.position;
				if (x4 < position8.x)
				{
					base.transform.Translate(Vector2.right * speed * Time.deltaTime);
					GetComponent<SkeletonAnimation>().skeleton.FlipX = false;
				}
				else
				{
					base.transform.Translate(-Vector2.right * speed * Time.deltaTime);
					GetComponent<SkeletonAnimation>().skeleton.FlipX = true;
				}
				SetAnim(AnimationName[typeOfEnemy][0], loop: true);
			}
			if (distance < distanceAttack && _target != null && !ishurt && !isNotSkill)
			{
				isattack = true;
				FlipEnemy();
				SetAnim(AnimationName[typeOfEnemy][3], loop: true);
			}
			if (distance > distanceAttack && _target != null)
			{
				isattack = false;
			}
		}
		else if (typeOfEnemy == 25 || typeOfEnemy == 26)
		{
			AllBoss12();
		}
		else if (typeOfEnemy == 27)
		{
			AllBoss3();
		}
		else if (typeOfEnemy == 28)
		{
			AllBoss4();
		}
		else
		{
			AllBoss56();
		}
	}

	private void FlipEnemy()
	{
		Vector3 position = base.transform.position;
		float x = position.x;
		Vector3 position2 = _target.transform.position;
		if (x < position2.x)
		{
			GetComponent<SkeletonAnimation>().skeleton.FlipX = false;
		}
		else
		{
			GetComponent<SkeletonAnimation>().skeleton.FlipX = true;
		}
	}

	private void FlipBoss()
	{
		Vector3 position = base.transform.position;
		float x = position.x;
		Vector3 position2 = _target.transform.position;
		if (x < position2.x)
		{
			GetComponent<SkeletonAnimation>().skeleton.FlipX = true;
		}
		else
		{
			GetComponent<SkeletonAnimation>().skeleton.FlipX = false;
		}
	}

	private void AllBoss12()
	{
		if (!isattack && !isdeath && !isAttacking)
		{
			Vector3 position = base.transform.position;
			float x = position.x;
			Vector3 position2 = _target.transform.position;
			if (x < position2.x)
			{
				base.transform.Translate(Vector2.right * speed * Time.deltaTime);
				GetComponent<SkeletonAnimation>().skeleton.FlipX = true;
			}
			else
			{
				base.transform.Translate(-Vector2.right * speed * Time.deltaTime);
				GetComponent<SkeletonAnimation>().skeleton.FlipX = false;
			}
			SetAnim(AnimationName[typeOfEnemy][0], loop: true);
		}
		if (typeOfEnemy == 25)
		{
			if (distance < 1.5f && _target != null && !isdeath)
			{
				isattack = true;
				isAttacking = true;
				FlipBoss();
				SetAnim(AnimationName[typeOfEnemy][1], loop: false);
			}
			if (distance > 1.5f && _target != null && !isdeath)
			{
				isattack = false;
			}
		}
		if (typeOfEnemy != 26)
		{
			return;
		}
		if (distance < 2.3f && _target != null && !isdeath)
		{
			isattack = true;
			isAttacking = true;
			FlipBoss();
			if (GetComponent<SkeletonAnimation>().AnimationName != AnimationName[typeOfEnemy][1] && attackofBoss3 % 2 == 0)
			{
				GetComponent<SkeletonAnimation>().state.SetAnimation(0, AnimationName[typeOfEnemy][1], loop: false);
			}
			if (GetComponent<SkeletonAnimation>().AnimationName != AnimationName[typeOfEnemy][3] && attackofBoss3 % 2 == 1)
			{
				GetComponent<SkeletonAnimation>().state.SetAnimation(0, AnimationName[typeOfEnemy][3], loop: false);
			}
		}
		if (distance > 2.3f && _target != null && !isdeath)
		{
			isattack = false;
		}
	}

	private void AllBoss3()
	{
		RaycastHit2D raycastHit2D = Physics2D.Raycast(base.transform.Find("attack1").transform.position, posPlayer - base.transform.Find("attack1").transform.position, 100f, ~(1 << LayerMask.NameToLayer("Enemy")));
		if (raycastHit2D.collider != null && isLaze && raycastHit2D.collider.CompareTag("Player"))
		{
			if (!isEff)
			{
				isEff = true;
				bcLaze = UnityEngine.Object.Instantiate(effHitlaze, raycastHit2D.point, effHitlaze.transform.rotation);
			}
			bcLaze.transform.position = raycastHit2D.point;
			UnityEngine.Object.Destroy(bcLaze, 1.2f);
			_target.GetComponent<PlayerController>().Hit_Enemy(70);
			if (lazeBoss3 != null)
			{
				lazeBoss3.GetComponent<LineRenderer>().SetPosition(1, raycastHit2D.point);
				childLazeBoss3.GetComponent<LineRenderer>().SetPosition(1, raycastHit2D.point);
			}
		}
		if (!isattack && !isdeath)
		{
			FlipBoss();
			SetAnim(AnimationName[typeOfEnemy][0], loop: true);
		}
		if (distance < 22f && distance > 13f && _target != null && !isdeath)
		{
			isattack = true;
			isAttacking = true;
			SetAnim(AnimationName[typeOfEnemy][1], loop: true);
		}
		if (distance < 13f && distance > 2.5f && _target != null && !isdeath && !isAttacking)
		{
			UnityEngine.Object.Destroy(lazeBoss3);
			isattack = true;
			SetAnim(AnimationName[typeOfEnemy][4], loop: true);
		}
		if (distance < 2.5f && _target != null && !isdeath)
		{
			isattack = true;
			SetAnim(AnimationName[typeOfEnemy][3], loop: true);
		}
	}

	private void AllBoss4()
	{
		if (!isattack && !isdeath && !isSkill && !isAttacking)
		{
			Vector3 position = base.transform.position;
			float x = position.x;
			Vector3 position2 = _target.transform.position;
			if (x < position2.x)
			{
				base.transform.Translate(Vector2.right * 1.5f * Time.deltaTime);
			}
			else
			{
				base.transform.Translate(-Vector2.right * 1.5f * Time.deltaTime);
			}
			SetAnim(AnimationName[typeOfEnemy][0], loop: true);
		}
		if (distance < 0.3f && _target != null && isComplete && !isdeath && !isMet)
		{
			isattack = true;
			isAttacking = true;
			if (AttackOfBoss4 == 0 && isComplete)
			{
				SetAnim(AnimationName[typeOfEnemy][1], loop: false);
			}
			if (AttackOfBoss4 == 1 && isComplete)
			{
				SetAnim(AnimationName[typeOfEnemy][3], loop: false);
			}
			if (AttackOfBoss4 == 4 && isComplete)
			{
				SetAnim(AnimationName[typeOfEnemy][4], loop: false);
			}
			if (AttackOfBoss4 == 5 && isComplete)
			{
				isSkill = true;
				isComplete = false;
				SetAnim(AnimationName[typeOfEnemy][5], loop: false);
			}
		}
		if (AttackOfBoss4 == 6 && isComplete)
		{
			isMet = true;
			GetComponent<SkeletonAnimation>().state.SetAnimation(0, AnimationName[typeOfEnemy][6], loop: true);
			AttackOfBoss4++;
		}
		if (AttackOfBoss4 > 6 && !isMet)
		{
			GetComponent<SkeletonAnimation>().state.SetAnimation(0, AnimationName[typeOfEnemy][7], loop: false);
		}
		if (AttackOfBoss4 < 0)
		{
			GetComponent<SkeletonAnimation>().state.SetAnimation(0, AnimationName[typeOfEnemy][0], loop: true);
		}
		if (distance > 0.3f && _target != null && !isdeath && isComplete)
		{
			isattack = false;
		}
	}

	private void AllBoss56()
	{
		if (!isattack && !isdeath && !isAttacking)
		{
			Vector3 position = base.transform.position;
			float x = position.x;
			Vector3 position2 = _target.transform.position;
			if (x < position2.x)
			{
				base.transform.Translate(Vector2.right * speed * Time.deltaTime);
				if (typeOfEnemy == 29)
				{
					GetComponent<SkeletonAnimation>().skeleton.FlipX = false;
				}
				else
				{
					GetComponent<SkeletonAnimation>().skeleton.FlipX = true;
				}
			}
			else
			{
				base.transform.Translate(-Vector2.right * speed * Time.deltaTime);
				if (typeOfEnemy == 29)
				{
					GetComponent<SkeletonAnimation>().skeleton.FlipX = true;
				}
				else
				{
					GetComponent<SkeletonAnimation>().skeleton.FlipX = false;
				}
			}
			SetAnim(AnimationName[typeOfEnemy][0], loop: true);
		}
		if (distance < 3f && _target != null && !isdeath && currentTime > 2.5f)
		{
			isattack = true;
			isAttacking = true;
			if (typeOfEnemy == 29)
			{
				if (GetComponent<SkeletonAnimation>().AnimationName != AnimationName[typeOfEnemy][1] && attackofBoss5 % 2 == 0)
				{
					GetComponent<SkeletonAnimation>().state.SetAnimation(0, AnimationName[typeOfEnemy][1], loop: false);
				}
				if (GetComponent<SkeletonAnimation>().AnimationName != AnimationName[typeOfEnemy][4] && attackofBoss5 % 2 == 1)
				{
					GetComponent<SkeletonAnimation>().state.SetAnimation(0, AnimationName[typeOfEnemy][4], loop: false);
				}
			}
			else
			{
				if (GetComponent<SkeletonAnimation>().AnimationName != AnimationName[typeOfEnemy][1] && attackofBoss6 % 2 == 0)
				{
					GetComponent<SkeletonAnimation>().state.SetAnimation(0, AnimationName[typeOfEnemy][1], loop: false);
				}
				if (GetComponent<SkeletonAnimation>().AnimationName != AnimationName[typeOfEnemy][4] && attackofBoss6 % 2 == 1)
				{
					GetComponent<SkeletonAnimation>().state.SetAnimation(0, AnimationName[typeOfEnemy][4], loop: false);
				}
			}
		}
		if (distance < 3f && _target != null && !isdeath && currentTime < 2.5f)
		{
			isattack = true;
			SetAnim(AnimationName[typeOfEnemy][3], loop: true);
		}
		if (distance > 3f && _target != null && !isdeath)
		{
			isattack = false;
		}
	}

	private void len()
	{
		AttackOfBoss4++;
		isMet = false;
		isSkill = false;
		HitOfBoss4 = 0;
		Invoke("normal", 3f);
		CancelInvoke("len");
	}

	private void normal()
	{
		AttackOfBoss4 = 0;
		CancelInvoke("normal");
	}

	private void OnCollisionEnter2D(Collision2D target)
	{
		if (typeOfEnemy > 24)
		{
			return;
		}
		if (target.gameObject.tag == "Platform" && isNga && countNga == 0)
		{
			Vector3 position = base.transform.position;
			float x = position.x;
			Vector3 position2 = _target.transform.position;
			if (x < position2.x)
			{
				GetComponent<Rigidbody2D>().AddForce(new Vector2(-0.6f, 1.2f) * UnityEngine.Random.Range(100, 150));
			}
			else
			{
				GetComponent<Rigidbody2D>().AddForce(new Vector2(0.6f, 1.2f) * UnityEngine.Random.Range(100, 150));
			}
			countNga++;
		}
		else if (target.gameObject.tag == "Platform" && isNga && countNga > 0)
		{
			isNga = false;
			if (typeOfEnemy < 15 || (typeOfEnemy > 18 && typeOfEnemy < 22))
			{
				SetAnim(AnimationName[typeOfEnemy][5], loop: false);
			}
			else
			{
				SetAnim(AnimationName[typeOfEnemy][4], loop: false);
			}
		}
		else if (target.gameObject.tag == "TheEnd")
		{
			Vector3 position3 = base.transform.position;
			float x2 = position3.x;
			Vector3 position4 = target.transform.position;
			if (x2 < position4.x)
			{
				GetComponent<Rigidbody2D>().AddForce(new Vector2(-1f, 0f) * 200f);
			}
			else
			{
				GetComponent<Rigidbody2D>().AddForce(new Vector2(1f, 0f) * 200f);
			}
		}
	}

	private void FindPlayer()
	{
		player = GameObject.FindGameObjectsWithTag("Player");
		for (int i = 0; i < player.Length; i++)
		{
			Vector3 position = base.transform.position;
			float x = position.x;
			Vector3 position2 = player[i].transform.position;
			distance = Mathf.Abs(x - position2.x);
			if (distance < 25f)
			{
				_target = player[i];
			}
		}
	}

	private void SetAnim(string nameAnim, bool loop)
	{
		if (skeletonAnimationHead.AnimationName != nameAnim)
		{
			skeletonAnimationHead.state.SetAnimation(0, nameAnim, loop);
		}
	}

	private void AnimationComplete(TrackEntry entry)
	{
		if (entry.animation.name != AnimationName[typeOfEnemy][0] && !isNga)
		{
			ishurt = false;
			isAttacking = false;
			chuyen = false;
			isComplete = true;
			isNotSkill = false;
			countAttack = 0;
			attackofBoss3++;
			if (AttackOfBoss4 > 6)
			{
				Invoke("len", 5f);
			}
		}
		if (typeOfEnemy == 29)
		{
			if (entry.animation.name == "attack" || entry.animation.name == "attack 2")
			{
				currentTime = 0f;
				attackofBoss5++;
			}
		}
		else if (typeOfEnemy == 30 && (entry.animation.name == "attack 1" || entry.animation.name == "attack 2"))
		{
			currentTime = 0f;
			attackofBoss6++;
		}
		if (entry.animation.name == "die")
		{
			UnityEngine.Object.Destroy(base.gameObject);
		}
	}

	private void ActiveSkill(TrackEntry entry, Spine.Event e)
	{
		if (e.Data.name == "attack")
		{
			if (typeOfEnemy < 15 || (typeOfEnemy >= 18 && typeOfEnemy < 27))
			{
				if (distance < distanceAttack)
				{
					_target.gameObject.GetComponent<PlayerController>().Hit_Enemy(damageEnemy);
				}
			}
			else if (typeOfEnemy == 28)
			{
				if (entry.animation.name == "attack1")
				{
					if (distance < distanceAttack)
					{
						_target.gameObject.GetComponent<PlayerController>().Hit_Enemy(damageEnemy);
					}
					isComplete = false;
					AttackOfBoss4++;
				}
				else if (entry.animation.name == "attack2")
				{
					GameObject gameObject = UnityEngine.Object.Instantiate(EffHitOfBoss4, base.transform.position + new Vector3(1.6f, 2.5f, 0f), Quaternion.identity);
					HitOfBoss4++;
					if (HitOfBoss4 == 1)
					{
						gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(-1f, -1f) * 200f);
					}
					if (HitOfBoss4 == 2)
					{
						gameObject.GetComponent<Rigidbody2D>().AddForce(-Vector2.up * 200f);
					}
					if (HitOfBoss4 == 3)
					{
						gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(1f, -1f) * 200f);
					}
					isComplete = false;
					AttackOfBoss4++;
				}
				else if (entry.animation.name == "attack3")
				{
					_target.gameObject.GetComponent<PlayerController>().Hit_Enemy(damageEnemy);
					isComplete = false;
					AttackOfBoss4++;
				}
				else if (entry.animation.name == "ulti")
				{
					UnityEngine.Object.Instantiate(EffSkillUltoBoss4, base.transform.position, Quaternion.identity);
				}
			}
			else if (typeOfEnemy == 29)
			{
				if (!(distance < 3f))
				{
					return;
				}
				if (entry.animation.name == "attack")
				{
					_target.gameObject.GetComponent<PlayerController>().Hit_Enemy(damageEnemy);
				}
				else if (entry.animation.name == "attack 2")
				{
					_target.gameObject.GetComponent<PlayerController>().Hit_Enemy(damageEnemy);
					Vector3 position = _target.transform.position;
					float x = position.x;
					Vector3 position2 = base.transform.position;
					if (x < position2.x)
					{
						_target.gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(-1.5f, 1.2f) * 3f;
					}
					else
					{
						_target.gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(1.5f, 1.2f) * 3f;
					}
					_target.GetComponent<PlayerController>().isBanra = true;
					StartCoroutine(isBanraFalse());
				}
			}
			else if (typeOfEnemy == 30)
			{
				if (!(distance < 3.5f))
				{
					return;
				}
				if (entry.animation.name == "attack 1")
				{
					_target.gameObject.GetComponent<PlayerController>().Hit_Enemy(damageEnemy);
				}
				else if (entry.animation.name == "attack 2")
				{
					_target.gameObject.GetComponent<PlayerController>().Hit_Enemy(damageEnemy);
					Vector3 position3 = _target.transform.position;
					float x2 = position3.x;
					Vector3 position4 = base.transform.position;
					if (x2 < position4.x)
					{
						_target.gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(-1.5f, 1.2f) * 3f;
					}
					else
					{
						_target.gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(1.5f, 1.2f) * 3f;
					}
					_target.GetComponent<PlayerController>().isBanra = true;
					StartCoroutine(isBanraFalse());
				}
			}
			else
			{
				GameObject gameObject2 = UnityEngine.Object.Instantiate(Bow, base.transform.Find("attack").transform.position, Quaternion.identity);
				Vector3 position5 = base.transform.position;
				float x3 = position5.x;
				Vector3 position6 = _target.transform.position;
				if (x3 < position6.x)
				{
					gameObject2.GetComponent<Rigidbody2D>().AddForce(Vector2.right * 400f);
					return;
				}
				gameObject2.GetComponent<Rigidbody2D>().AddForce(-Vector2.right * 400f);
				gameObject2.transform.localScale = new Vector3(-1f, 1f, 1f);
			}
		}
		else if (e.Data.name == "down")
		{
			Transform transform = base.transform;
			Vector3 position7 = base.transform.position;
			transform.DOMoveY(position7.y - 2.5f, 1f);
			AttackOfBoss4++;
		}
		else if (e.Data.name == "up")
		{
			if (!isdeath)
			{
				AttackOfBoss4 = -1;
				Transform transform2 = base.transform;
				Vector3 position8 = base.transform.position;
				transform2.DOMoveY(position8.y + 2.5f, 1f);
			}
		}
		else if (e.Data.name == "attack 1")
		{
			if (entry.animation.name == "attack")
			{
				AudioController.Instance.SoundLazeBoss3();
				lazeBoss3 = UnityEngine.Object.Instantiate(Laze, base.transform.position, Quaternion.identity);
				childLazeBoss3 = UnityEngine.Object.Instantiate(childLaze, base.transform.position, Quaternion.identity);
				LineRenderer component = lazeBoss3.GetComponent<LineRenderer>();
				Vector3 position9 = base.transform.Find("attack1").transform.position;
				float x4 = position9.x;
				Vector3 position10 = base.transform.Find("attack1").transform.position;
				component.SetPosition(0, new Vector3(x4, position10.y, -1f));
				LineRenderer component2 = lazeBoss3.GetComponent<LineRenderer>();
				Vector3 position11 = GameObject.FindGameObjectWithTag("Player").transform.position;
				float x5 = position11.x;
				Vector3 position12 = GameObject.FindGameObjectWithTag("Player").transform.position;
				component2.SetPosition(1, new Vector3(x5, position12.y + 0.3f, -1f));
				posPlayer = GameObject.FindGameObjectWithTag("Player").transform.position;
			}
			else if (entry.animation.name == "attack2")
			{
				if (distance < 2.5f)
				{
					_target.gameObject.GetComponent<PlayerController>().Hit_Enemy(damageEnemy);
					_target.gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(-1.5f, 0.8f) * 5f;
					_target.GetComponent<PlayerController>().isBanra = true;
					StartCoroutine(isBanraFalse());
				}
			}
			else if (entry.animation.name == "attack3")
			{
				GameObject gameObject3 = UnityEngine.Object.Instantiate(Bom, base.transform.Find("attack").transform.position, Quaternion.identity);
				GameManager.AllBoom.Add(gameObject3);
				float angle = 30f;
				Vector3 a = Quaternion.AngleAxis(angle, Vector3.forward) * new Vector3(0f, 1f, 1f);
				gameObject3.GetComponent<Rigidbody2D>().AddForce(a * UnityEngine.Random.Range(200, 600));
			}
		}
		else if (e.Data.name == "attack 2")
		{
			AudioController.Instance.SoundPlayeLazeBoss3();
			isLaze = true;
			LineRenderer component3 = childLazeBoss3.GetComponent<LineRenderer>();
			Vector3 position13 = base.transform.Find("attack1").transform.position;
			float x6 = position13.x;
			Vector3 position14 = base.transform.Find("attack1").transform.position;
			component3.SetPosition(0, new Vector3(x6, position14.y, -1f));
			childLazeBoss3.GetComponent<LineRenderer>().SetPosition(1, new Vector3(posPlayer.x, posPlayer.y, -1f));
			StartCoroutine(deleteRayCast());
			UnityEngine.Object.Destroy(lazeBoss3, 1f);
			UnityEngine.Object.Destroy(childLazeBoss3, 1f);
		}
		else if (e.ToString() == "chuyen")
		{
			countAttack++;
		}
	}

	private IEnumerator deleteRayCast()
	{
		yield return new WaitForSeconds(1f);
		isLaze = false;
		isEff = false;
	}

	public void Hit_Player(int damage, bool a, int wayDeath)
	{
		damage *= GameManager.hesotangdame;
		if (typeOfEnemy == 28 && !isMet)
		{
			damage = 0;
		}
		HealthMaxEnemy -= damage;
		StartCoroutine(changeAnimation());
		ClipHealthEnemy.ClipRect = new Rect(ClipHealthEnemy.ClipRect.x + (float)damage / localHealthEnemy, 0f, 1f, 1f);
		if (HealthMaxEnemy <= 0f && !isdeath)
		{
			ishurt = false;
			isdeath = true;
			if (typeOfEnemy < 25)
			{
				if (_target != null)
				{
					GetComponent<Collider2D>().enabled = false;
					UnityEngine.Object.Destroy(GetComponent<Rigidbody2D>());
					if (wayDeath < 2)
					{
						Vector3 position = base.transform.position;
						float x = position.x;
						Vector3 position2 = _target.transform.position;
						if (x < position2.x)
						{
							GetComponent<SkeletonRagdoll2D>().Apply();
							GetComponent<SkeletonRagdoll2D>().gravityScale = 1f;
							switch (wayDeath)
							{
							case 0:
								GetComponent<SkeletonRagdoll2D>().RootRigidbody.AddForce(new Vector2(-0.7f, 1.5f) * UnityEngine.Random.Range(10000, 14000));
								break;
							case 1:
								GetComponent<SkeletonRagdoll2D>().RootRigidbody.AddForce(new Vector2(-0.7f, 1.5f) * UnityEngine.Random.Range(8000, 9000));
								break;
							}
						}
						else
						{
							GetComponent<SkeletonRagdoll2D>().Apply();
							GetComponent<SkeletonRagdoll2D>().gravityScale = 1f;
							switch (wayDeath)
							{
							case 0:
								GetComponent<SkeletonRagdoll2D>().RootRigidbody.AddForce(new Vector2(0.7f, 1.5f) * UnityEngine.Random.Range(10000, 14000));
								break;
							case 1:
								GetComponent<SkeletonRagdoll2D>().RootRigidbody.AddForce(new Vector2(0.7f, 1.5f) * UnityEngine.Random.Range(8000, 9000));
								break;
							}
						}
						GetComponent<SkeletonAnimation>().state.SetAnimation(0, AnimationName[typeOfEnemy][2], loop: true);
						Invoke("changeColor", 1.3f);
					}
					else
					{
						Vector3 position3 = base.transform.position;
						float x2 = position3.x;
						Vector3 position4 = _target.transform.position;
						if (x2 < position4.x)
						{
							GetComponent<ExplosionRagdoll2D>().isLeft = true;
						}
						else
						{
							GetComponent<ExplosionRagdoll2D>().isLeft = false;
						}
						GetComponent<SkeletonAnimation>().state.SetAnimation(0, AnimationName[typeOfEnemy][2], loop: true);
						GetComponent<Rigidbody2D>().isKinematic = true;
						GetComponent<ExplosionRagdoll2D>().Apply();
						GetComponent<Collider2D>().enabled = false;
						Invoke("changeColor", 1.3f);
					}
				}
				else
				{
					GetComponent<Collider2D>().enabled = false;
					GetComponent<Rigidbody2D>().isKinematic = true;
					GetComponent<SkeletonRagdoll2D>().Apply();
					GetComponent<SkeletonRagdoll2D>().gravityScale = 1f;
					Invoke("changeColor", 0.5f);
				}
				AudioController.Instance.SoundEnemyDeath();
			}
			else if ((typeOfEnemy >= 25 && typeOfEnemy < 28) || typeOfEnemy > 28)
			{
				AudioController.Instance.SoundBoss123Die();
				StartCoroutine(InstanceGoldBoss());
				GameManager.isBossDeath = true;
			}
			else if (typeOfEnemy == 28)
			{
				CancelInvoke("len");
				AudioController.Instance.SoundBoss4Die();
				StartCoroutine(InstanceGoldBoss());
				GameManager.isBossDeath = true;
			}
			if (this.EnemyKilled != null)
			{
				this.EnemyKilled(this, EventArgs.Empty);
			}
			int num = UnityEngine.Random.Range(0, 100);
			if (num <= dropcoin)
			{
				StartCoroutine(InstanceGold());
			}
			else if (num > 90 && num <= 93)
			{
				UnityEngine.Object.Instantiate(Item[1], base.transform.position, Quaternion.identity);
			}
			else if (num > 93 && num <= 96)
			{
				UnityEngine.Object.Instantiate(Item[2], base.transform.position, Quaternion.identity);
			}
		}
		if (_target != null && !isdeath)
		{
			Vector3 position5 = base.transform.position;
			float x3 = position5.x;
			Vector3 position6 = _target.transform.position;
			if (x3 < position6.x)
			{
				GameObject obj = UnityEngine.Object.Instantiate(blood1, base.transform.position + new Vector3(0f, 0.7f, 0f), blood1.transform.rotation);
				UnityEngine.Object.Destroy(obj, 0.8f);
			}
			else
			{
				GameObject obj2 = UnityEngine.Object.Instantiate(blood, base.transform.position + new Vector3(0f, 0.7f, 0f), blood.transform.rotation);
				UnityEngine.Object.Destroy(obj2, 0.8f);
			}
		}
		if (typeOfEnemy < 25)
		{
			AudioController.Instance.SoundBlood();
			if (a)
			{
				ishurt = true;
				isNotSkill = false;
			}
			if (!a)
			{
				isNotSkill = true;
				ishurt = false;
			}
			if (ishurt && !isNotSkill && !isNga && !isdeath)
			{
				GetComponent<Rigidbody2D>().AddForce(Vector2.up * UnityEngine.Random.Range(100, 140));
				isNga = true;
				countNga = 0;
				GetComponent<SkeletonAnimation>().state.SetAnimation(0, AnimationName[typeOfEnemy][2], loop: false);
				isComplete = false;
			}
			if (isNotSkill && !ishurt)
			{
				GetComponent<SkeletonAnimation>().state.SetAnimation(0, AnimationName[typeOfEnemy][1], loop: false);
				isComplete = false;
			}
		}
	}

	private IEnumerator InstanceGold()
	{
		int V = UnityEngine.Random.Range(1, 3);
		for (int i = 0; i < V; i++)
		{
			UnityEngine.Object.Instantiate(Item[0], base.transform.position + new Vector3(0f, 0.5f, 0f), Quaternion.identity);
			yield return new WaitForSeconds(0.2f);
		}
	}

	private IEnumerator InstanceGoldBoss()
	{
		for (int i = 0; i < 8; i++)
		{
			UnityEngine.Object.Instantiate(Item[0], base.transform.position + new Vector3(0f, 0.5f, 0f), Quaternion.identity);
			yield return new WaitForSeconds(0.05f);
		}
	}

	private IEnumerator changeAnimation()
	{
		yield return new WaitForSeconds(0.3f);
		ishurt = false;
	}

	private IEnumerator isBanraFalse()
	{
		yield return new WaitForSeconds(1f);
		_target.GetComponent<PlayerController>().isBanra = false;
	}

	private void changeColor()
	{
		skeletonAnimationHead.skeleton.a -= 0.05f;
		Invoke("changeColor", 0.1f);
		if ((double)skeletonAnimationHead.skeleton.a < 0.0)
		{
			UnityEngine.Object.Destroy(base.gameObject);
			GameManager.AllEnemy.Remove(base.gameObject);
		}
	}
}
